// 引入接口文件
import {exportConlog} from './conlogListServ.js'

// 对象和JSON字符串互转
import { parse } from 'qs'
// 弹出消息框
import { message } from 'antd'
// 日期处理对象
import moment from 'moment'
/* isEmpty 对象是否为空
 * isArray 对象是否数组
 * cloneDeep 对象深拷贝
 */
import {isEmpty, isArray, cloneDeep, merge} from 'lodash'
// 引入路由对象
import { hashHistory } from 'dva/router'
import { makeAddress } from "utils/util"
// 初始默认状态
const defultState = {
  loading: false,
  btnLoading: false,
  biz: {
		queryForm: {}
	},
  queryList: {}
}
// 声明module
const tmpModule = {
  namespace: 'messageListModel',
  state: cloneDeep(defultState),
  subscriptions: {
    setup ({dispatch, history}) {
      history.listen(({ pathname, query }) => {
        if('' + tmpModule.pathname === '' + pathname){
          dispatch({ type: 'updateStore', payload: cloneDeep(defultState) });
          dispatch({ type: 'typeList', payload: {} });
        }
      })
    },
  },
  // 方法列表
  effects: {
    *exportConlog({ payload }, { put, call, select }) {
      let { queryList } = yield select(state => state[tmpModule.namespace])
      console.log(queryList)
      let params = { pageSize: 9999, pageNo: 1, ...queryList }
      let { data, success } = yield call(exportConlog, params)
      if (success) {
          //console.log(data)
          message.success('导出成功,正在为您下载表格')
          window.location.href = data
      }
  }
  },
  
 

  // 存入状态机
  reducers: {
    updateStore(preState, action) {
      return { ...preState, ...action.payload };
    }
  }
}

export default tmpModule
